#pragma once

#include "Win32Dialog.h"

START_NAMESPACE

class CWin32Control_Base : public CWindowBase
{
public:
	virtual void SetFont(HFONT hFont);
	virtual void SetText(LPCSTR text);
	virtual void SetText(int value);
	virtual void GetText(std::string& str);
};

class CWin32Control_Static : public CWin32Control_Base
{
public:
	bool Create(HINSTANCE hInstance,HWND hParent,UINT nID,DWORD dwStyle,DWORD dwExStyle,int x,int y,int xsize,int ysize);	

};

class CWin32Control_EditBox : public CWin32Control_Base
{
public:
	bool Create(HINSTANCE hInstance,HWND hParent,UINT nID,DWORD dwStyle,DWORD dwExStyle,int x,int y,int xsize,int ysize);
};

class CWin32Control_Button : public CWin32Control_Base
{
public:
	bool Create(HINSTANCE hInstance,HWND hParent,UINT nID,DWORD dwStyle,DWORD dwExStyle,int x,int y,int xsize,int ysize);
};

class CWin32Control_PopupMenu
{
public:
	CWin32Control_PopupMenu();
	virtual ~CWin32Control_PopupMenu();

	void AppendMenu(UINT nFlags,UINT nItemID,LPCSTR szItem,...);
	void AppendSeparator();
	CWin32Control_PopupMenu* AppendPopupMenu(LPCSTR szMenuName,...);
	int TrackPopupMenu(HWND hWnd);

	inline HMENU GetHandle(){ return m_hMenu;}
protected:
	HMENU m_hMenu;

	typedef std::list<CWin32Control_PopupMenu*> POPUPMENU_LIST;
	POPUPMENU_LIST	m_PopupMenuList;
};

class CWin32PropertyDialog : public CWin32Dialog
{
public:
	CWin32PropertyDialog(HINSTANCE hInstance,UINT TemplateID,CWindowBase *pWndParent = NULL,BOOL bEditBoxDoNotEmpty = TRUE);
	virtual ~CWin32PropertyDialog();
	
	LRESULT OnInitDialog(WPARAM wParam,LPARAM lParam);
	LRESULT OnOk(WPARAM wParam,LPARAM lParam);

	LPCSTR GetText(UINT id);

	void	PrepareText(UINT id,LPCSTR text,BOOL bReadOnly = FALSE);
	
	void AddText(UINT id,LPCSTR text);
	BOOL IsEditBoxDoNotEmpty(){ return m_bEditBoxDoNotEmpty;}

protected:
	typedef std::map<UINT,std::string> TEXT_MAP;
	TEXT_MAP							m_TextMap;
	BOOL								m_bEditBoxDoNotEmpty;

	struct sPreparedText
	{
		UINT m_nID;
		std::string m_szText;
		BOOL m_bEnable;
	};

	typedef std::list<sPreparedText*> PREPARED_TEXT_LIST;
	PREPARED_TEXT_LIST					m_PreparedTextList;
};

//
namespace ListView
{
extern void InsertColumn( HWND hWnd,int iSubIndex,LPCSTR text,int width,DWORD format);
extern int InsertItem( HWND hWnd,LPCSTR text,DWORD dwParam = 0);
extern void SetItemText(HWND hWnd,int iIndex,int iSubIndex,LPCSTR format,...);
extern DWORD GetItemData(HWND hWnd,int iIndex);
extern int GetSelectedItem(HWND hWnd);
extern int GetFirstItemIndex(HWND hWnd);
extern std::string GetItemText(HWND hWnd,int iIndex,int iSubIndex);
extern void CopyToClipboard(HWND hWnd,int column_count);
extern void SetCheck(HWND hWnd,int index,BOOL bTrue);
extern BOOL GetCheck(HWND hWnd,int index);
}

namespace ComboBox
{
extern int AddString(HWND hWnd,DWORD dwItemData,LPCSTR format,...);
extern void DeleteAll(HWND hWnd);
extern int  GetCurSel(HWND hWnd);
extern DWORD GetItemData(HWND hWnd,int index);
extern void SetCurSel(HWND hWnd,int index);
extern DWORD GetSelectedItemData(HWND hWnd);
void SetCurSelByString(HWND hWnd, LPCSTR name);
};

extern UINT MessageBoxF(HWND hParentWnd,LPCSTR szTitle,UINT flag,LPCSTR szFormat,...);

namespace DateTime
{
extern std::string GetDateTimeString(HWND hDate,HWND hTime);
extern void SetDateTime(HWND hParent,UINT iDate,UINT iTime,SYSTEMTIME& time);
extern SYSTEMTIME GetDateTime(HWND hParent,UINT iDate,UINT iTime);
extern std::string MakeStringFromSystemTime(SYSTEMTIME& time);

/////////////////////////////////////////////////////////////////////////////
// CTimeSpan and CTime

class CTimeSpan
{
public:

// Constructors
	CTimeSpan();
	CTimeSpan(time_t time);
	CTimeSpan(LONG lDays, int nHours, int nMins, int nSecs);

	CTimeSpan(const CTimeSpan& timeSpanSrc);
	const CTimeSpan& operator=(const CTimeSpan& timeSpanSrc);

// Attributes
	// extract parts
	LONG GetDays() const;   // total # of days
	LONG GetTotalHours() const;
	int GetHours() const;
	LONG GetTotalMinutes() const;
	int GetMinutes() const;
	LONG GetTotalSeconds() const;
	int GetSeconds() const;

// Operations
	// time math
	CTimeSpan operator-(CTimeSpan timeSpan) const;
	CTimeSpan operator+(CTimeSpan timeSpan) const;
	const CTimeSpan& operator+=(CTimeSpan timeSpan);
	const CTimeSpan& operator-=(CTimeSpan timeSpan);
	BOOL operator==(CTimeSpan timeSpan) const;
	BOOL operator!=(CTimeSpan timeSpan) const;
	BOOL operator<(CTimeSpan timeSpan) const;
	BOOL operator>(CTimeSpan timeSpan) const;
	BOOL operator<=(CTimeSpan timeSpan) const;
	BOOL operator>=(CTimeSpan timeSpan) const;

private:
	time_t m_timeSpan;
	friend class CTime;
};

class CTime
{
public:

// Constructors
	static CTime PASCAL GetCurrentTime();

	CTime();
	CTime(time_t time);
	CTime(int nYear, int nMonth, int nDay, int nHour, int nMin, int nSec,
		int nDST = -1);
	CTime(WORD wDosDate, WORD wDosTime, int nDST = -1);
	CTime(const CTime& timeSrc);

	CTime(const SYSTEMTIME& sysTime, int nDST = -1);
	CTime(const FILETIME& fileTime, int nDST = -1);
	const CTime& operator=(const CTime& timeSrc);
	const CTime& operator=(time_t t);

// Attributes
	struct tm* GetGmtTm(struct tm* ptm = NULL) const;
	struct tm* GetLocalTm(struct tm* ptm = NULL) const;
	BOOL GetAsSystemTime(SYSTEMTIME& timeDest) const;

	time_t GetTime() const;
	int GetYear() const;
	int GetMonth() const;       // month of year (1 = Jan)
	int GetDay() const;         // day of month
	int GetHour() const;
	int GetMinute() const;
	int GetSecond() const;
	int GetDayOfWeek() const;   // 1=Sun, 2=Mon, ..., 7=Sat

// Operations
	// time math
	CTimeSpan operator-(CTime time) const;
	CTime operator-(CTimeSpan timeSpan) const;
	CTime operator+(CTimeSpan timeSpan) const;
	const CTime& operator+=(CTimeSpan timeSpan);
	const CTime& operator-=(CTimeSpan timeSpan);
	BOOL operator==(CTime time) const;
	BOOL operator!=(CTime time) const;
	BOOL operator<(CTime time) const;
	BOOL operator>(CTime time) const;
	BOOL operator<=(CTime time) const;
	BOOL operator>=(CTime time) const;

	// formatting using "C" strftime
//	std::string Format(LPCSTR pFormat) const;
//	std::string FormatGmt(LPCSTR pFormat) const;
//	std::string Format(UINT nFormatID) const;
//	std::string FormatGmt(UINT nFormatID) const;

private:
	tm		m_tm;
	time_t	m_time;
};



};


#define SET_CTRL_FONT(id, size)	\
	CWindowBase::SetNationalFont(GetDlgItem(id), size);

END_NAMESPACE